package com.PVZ.model.cards;

import com.PVZ.model.emuns.Configs;
import com.PVZ.model.emuns.PlantType;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import javax.imageio.ImageIO;
import javax.swing.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.util.Map;

/**
 * Created by @Author: kabuda on @Date: 2021/5/24 22:19
 */
@Getter
@Setter
@NoArgsConstructor
public class PlantCard extends JButton {

    // public static final int WIDTH = 52;
    public static final int WIDTH = 60;
    public static final int HEIGHT = 70;

    //是否可以点击
    public Boolean clickStatus = true;
    private PlantType plantType;
    /**
     * 冷却时间
     * 单位: s秒 最长72秒
     */
    private Integer coolDown = 0;
    private int position;
    private Configs configs;
    private int cardNumber = 1;
    private String plantImage;
    private BufferedImage lightImage;
    private BufferedImage grayImage;
    private BufferedImage  curImage;
    private BufferedImage  uCurImage;

    /**
     *  当前冷却时间
     */
    private Double curTime = 0.0;

    /**
     * 售价
     */
    private int value;

    public PlantCard(PlantType plantType, int x) {
        this.plantType = plantType;
        this.position = x;
        String srcPath = "res/img/card/";
        String plantImagePath = "res/img/plantPng/";

        try {
            switch (plantType) {

                case SunFlower: {
                    value=50;
                    lightImage = ImageIO.read(new File(srcPath + "SunFlower/SunFlower0.png"));
                    plantImage = plantImagePath + "SunFlower/SunFlower-5.png";
                    grayImage = ImageIO.read(new File(srcPath + "SunFlower/SunFlower2.png"));
                    break;
                }
                case PeaShooterSingle: {
                    value=100;
                    lightImage = ImageIO.read(new File(srcPath + "PeaShooterSingle/PeaShooterSingle0.png"));
                    plantImage = plantImagePath + "PeaShooterSingle/PeaShooterSingle-80.png";
                    grayImage = ImageIO.read(new File(srcPath + "PeaShooterSingle/PeaShooterSingle2.png"));
                    break;
                }case WallNut: {
                    value=50;
                    lightImage = ImageIO.read(new File(srcPath + "WallNut/WallNut0.png"));
                    plantImage = plantImagePath + "Wallnut/Wallnut-12.png";
                    grayImage = ImageIO.read(new File(srcPath + "WallNut/WallNut2.png"));
                    break;
                }
                case PeaShooter: {
                    value=200;
                    lightImage = ImageIO.read(new File(srcPath + "PeaShooter/PeaShooter0.png"));
                    plantImage = plantImagePath + "PeaShooter/PeaShooter-12.png";
                    grayImage = ImageIO.read(new File(srcPath + "PeaShooter/PeaShooter2.png"));
                    break;
                }
                case Caltrop: {
                    value=100;
                    lightImage = ImageIO.read(new File(srcPath + "PeaShooter/PeaShooter0.png"));
                    plantImage = plantImagePath + "Caltrop/Caltrop-1.png";
                    grayImage = ImageIO.read(new File(srcPath + "PeaShooter/PeaShooter2.png"));
                    break;
                }
                //暂时用双枪替图
                case CherryBomb: {
                    value=150;
                    lightImage = ImageIO.read(new File(srcPath + "CherryBomb/CherryBomb0.png"));
                    plantImage = plantImagePath + "CherryBomb/CherryBomb-5.png";
                    grayImage = ImageIO.read(new File(srcPath + "CherryBomb/CherryBomb2.png"));
                    break;
                }
                //暂时用双枪替图
                case Tallnut: {
                    value=100;
                    lightImage = ImageIO.read(new File(srcPath + "Tallnut/tallnut.png"));
                    plantImage = plantImagePath + "Tallnut/Tallnut-5.png";
                    grayImage = ImageIO.read(new File(srcPath + "Tallnut/tallnut-1.png"));
                    break;
                }
                case PotatoMine: {
                    value=25;
                    lightImage = ImageIO.read(new File(srcPath + "PotatoMine/PotatoMine0.png"));
                    plantImage = plantImagePath + "PotatoMine/PotatoMine-5.png";
                    grayImage = ImageIO.read(new File(srcPath + "PotCatoMine/PotatoMine2.png"));
                    break;
                }
                //暂时用土豆雷替图
                case Pumpkin: {
                    value=125;
                    lightImage = ImageIO.read(new File(srcPath + "PotatoMine/PotatoMine0.png"));
                    plantImage = plantImagePath + "Pumpkin/Pumpkin-5.png";
                    grayImage = ImageIO.read(new File(srcPath + "PotatoMine/PotatoMine2.png"));
                    break;
                }
                default: {
                    break;
                }
            }
        }catch(Exception e){
            e.printStackTrace();
        }

        curImage = lightImage;
        uCurImage=grayImage;
        setSize(WIDTH, HEIGHT);

        //设置冷却时间
        coolDown = Configs.cardCoolDown.get(plantType);
        Map<PlantType, Integer> golds = Configs.golds;


    }

}
